<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>

    const obj = {
        name:"admin"
    }

    function Parent(m){
        this.msg = m;
    }
    Parent.prototype.init = function(){
        console.log(this.msg)
    }

    function Child(m){
        this.msg = m;
    }

    // 原型对象继承（拷贝要继承的原型对象）
    // 注意深浅拷贝：要是用深拷贝
    // Child.prototype = Parent.prototype;
    // 深拷贝1
    // for(let i in Parent.prototype){
    //     Child.prototype[i] = Parent.prototype[i];
    // }
    // Child.prototype.init = function(){
    //     console.log("hahahhha")
    // }
    // 深拷贝2
    Child.prototype = {
        ...Parent.prototype,
        ...obj,
        // init(){
        //     console.log("hahahaha")
        // }
    }

    
    const p = new Parent("hello");
    console.log(p)
    p.init();
    console.log(p.init);
    
    const c = new Child("world");
    console.log(c)
    console.log(c.name)
    c.init();
    console.log(c.init);
    
</script>
</html>